﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Things.Common;
using LTP.Accounts.Bus;
namespace Things.ThingsWeb.Buyer
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					string Account= Request.Params["id"];
					ShowInfo(Account);
				}
			}
		}
			
	private void ShowInfo(string Account)
	{
		Things.BLL.Buyer bll=new Things.BLL.Buyer();
		Things.Model.Buyer model=bll.GetModel(Account);
		this.lblAccount.Text=model.Account;
		this.txtPassword.Text=model.Password;
		this.chkIsDisabled.Checked=model.IsDisabled;
		this.txtCreatedDate.Text=model.CreatedDate.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtPassword.Text.Trim().Length==0)
			{
				strErr+="密码不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCreatedDate.Text))
			{
				strErr+="创建时间格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			string Account=this.lblAccount.Text;
			string Password=this.txtPassword.Text;
			bool IsDisabled=this.chkIsDisabled.Checked;
			DateTime CreatedDate=DateTime.Parse(this.txtCreatedDate.Text);


			Things.Model.Buyer model=new Things.Model.Buyer();
			model.Account=Account;
			model.Password=Password;
			model.IsDisabled=IsDisabled;
			model.CreatedDate=CreatedDate;

			Things.BLL.Buyer bll=new Things.BLL.Buyer();
			bll.Update(model);
			Things.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
